<?php

namespace App\Http\Middleware;

use App\Lib\PvLog;
use Closure;
use App\Http\Model\User;

class PvLogMiddleware
{
    protected $model_user;

    public function __construct(User $user)
    {
        $this->model_user = $user;
    }

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        //记录用户活跃
        $this->model_user->saveUserActive();

        //记录用户tdid
        $this->model_user->saveUserTdid(empty($_SERVER['HTTP_TDID'])?'':$_SERVER['HTTP_TDID']);

        PvLog::$request = $request;
        PvLog::$startTime = microtime(true);
        return $next($request);
    }
}
